package net.wanho.t_question.question.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.wanho.entity.pojo.question.QuestionBank;
import net.wanho.t_question.question.service.QuestionService;
import net.wanho.t_question.question.service.impl.QuestionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class QuestionController {
    @Autowired
    QuestionService questionService;

    @GetMapping("/query/question/list/{pageNum}/{pageSize}")
    public JSONObject findQuestionList(@PathVariable("pageNum") int pageNum,@PathVariable("pageSize") int pageSize){
        JSONObject jsonObject = new JSONObject();
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<QuestionBank> questionBankList = questionService.findQuestionBankList();
            PageInfo pageInfo = new PageInfo(questionBankList);
            jsonObject.put("success",true);
            jsonObject.put("list",pageInfo);
        }catch (Exception e){
            jsonObject.put("message","查询所有问题失败！");
        }
        return jsonObject;
    }

    @PostMapping("/insert/question")
    public JSONObject insertQuestionData(@RequestBody QuestionBank questionBank){
        JSONObject jsonObject = new JSONObject();
        try {
            questionService.insertQuestionData(questionBank);
            jsonObject.put("success",true);
        }catch (Exception e){
            jsonObject.put("message","新增问题失败！");
        }
        return jsonObject;
    }
}
